package com.xoa.service.fixAssets;

import com.alibaba.fastjson.JSON;
import com.xoa.dao.common.SysCodeMapper;
import com.xoa.dao.common.SysParaMapper;
import com.xoa.dao.department.DepartmentMapper;
import com.xoa.dao.fixAssets.CpAssetsApplyMapper;
import com.xoa.dao.fixAssets.CpAssetsInventoryMapper;
import com.xoa.dao.fixAssets.CpAssetsInventoryRecordsMapper;
import com.xoa.dao.fixAssets.EduFixAssetsMapper;
import com.xoa.dao.sms.SmsMapper;
import com.xoa.dao.users.UsersMapper;
import com.xoa.dao.workflow.FlowTypeModelMapper;
import com.xoa.model.HSTmeeting.HstMeetingWithBLOBs;
import com.xoa.model.common.SysCode;
import com.xoa.model.common.SysPara;
import com.xoa.model.department.Department;
import com.xoa.model.enclosure.Attachment;
import com.xoa.model.fixAssets.*;
import com.xoa.model.sms.SmsBody;
import com.xoa.model.users.Users;
import com.xoa.model.workflow.FlowFast;
import com.xoa.model.workflow.FlowTypeModel;
import com.xoa.service.WFE.WFERunner.WFEFlowRunInfo;
import com.xoa.service.enclosure.EnclosureService;
import com.xoa.dao.emergency.CrashDispatchMapper;
import com.xoa.model.emergency.CrashDispatch;
import com.xoa.model.emergency.CrashDispatchWithBLOBs;
import com.xoa.service.sms.SmsService;
import com.xoa.service.smsDelivery.Sms2PrivService;
import com.xoa.util.*;
import com.xoa.util.common.L;
import com.xoa.util.common.StringUtils;
import com.xoa.util.common.log.FileUtils;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.dataSource.ContextHolder;
import com.xoa.util.page.PageParams;
import jdk.nashorn.internal.runtime.regexp.JoniRegExp;
import net.sf.ehcache.search.aggregator.Count;
import org.apache.commons.collections4.map.HashedMap;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.FormulaError;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.*;

import static com.xoa.util.FileUploadUtil.allowUpload;


@Service
public class  EduFixAssetsService{

    @Resource
    private EduFixAssetsMapper eduFixAssetsMapper;

    @Resource
    private CrashDispatchMapper crashDispatchMapper;

    @Resource
    private UsersMapper usersMapper;

    @Resource
    private DepartmentMapper departmentMapper;


    @Resource
    private FlowTypeModelMapper flowTypeModelMapper;

    @Autowired
    private WFEFlowRunInfo wfeFlowRunInfo;

    @Autowired
    private SysCodeMapper sysCodeMapper;

    @Autowired
    private SysParaMapper sysParaMapper;

    @Autowired
    private EnclosureService enclosureService;

    @Autowired
    private CpAssetsApplyMapper cpAssetsApplyMapper;

    @Autowired
    private CpAssetsInventoryMapper cpAssetsInventoryMapper;

    @Autowired
    private CpAssetsInventoryRecordsMapper cpAssetsInventoryRecordsMapper;

    @Resource
    ThreadPoolTaskExecutor threadPoolTaskExecutor;

    @Resource
    private SmsService smsService;

    @Resource
    private SmsMapper smsMapper;


    /**
     * 创建作者:   牛江丽
     * 创建日期:   2017年9月8日 下午16:38:00
     * 方法介绍:   根据条件查询固定资产（所有添加满足）
     * 参数说明:   @param eduFixAssets
     * 返回值说明:
     */
    public ToJson<EduFixAssets> selFixAssetsByCond(int condition, int output, EduFixAssets eduFixAssets, HttpServletRequest request, HttpServletResponse response, HttpSession session, Integer page, Integer pageSize, boolean useFlag) {
        ToJson<EduFixAssets> json = new ToJson<EduFixAssets>(1, "error");
        try {
            //分页
            PageParams pageParams = new PageParams();
            pageParams.setPage(page);
            pageParams.setPageSize(pageSize);
            pageParams.setUseFlag(useFlag);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("page", pageParams);
            SysCode sysCode = new SysCode();
            sysCode.setCodeName(eduFixAssets.getCurrutLocation());
            sysCode.setParentNo("LOCATION_ADDRESS");
            SysCode sysCode1 = sysCodeMapper.getCodeNoByNameAndParentNo(sysCode);
            if (sysCode1 != null) {
                eduFixAssets.setCurrutLocation(String.valueOf(sysCode1.getCodeNo()));
            }
            if (!StringUtils.checkNull(eduFixAssets.getKeeper())) {
                eduFixAssets.setKeeper(eduFixAssets.getKeeper() + ",");
            }
            map.put("eduFixAssets", eduFixAssets);
            List<EduFixAssets> eduFixAssetsList = new ArrayList<EduFixAssets>();

            if (condition == 1) {//condition==1,则进行资产名称的模糊查询
                eduFixAssetsList = eduFixAssetsMapper.selFixAssetsNameLike(map);
                json.setTotleNum(pageParams.getTotal());
            } else if (condition == 2) {//condition==2，则进行全部满足查询
                eduFixAssetsList = eduFixAssetsMapper.selAssetsByCond(map);
                json.setTotleNum(pageParams.getTotal());
            } else {//condition==3，则进行任意条件满足查询
                eduFixAssetsList = eduFixAssetsMapper.selAssetsByOrCond(map);
                json.setTotleNum(pageParams.getTotal());
            }
            EduFixAssets eduFixAssets11 = new EduFixAssets();

            if (output == 1) {//output==1,则进行导出操作
                if (eduFixAssetsList != null && eduFixAssetsList.size() > 0) {
                    for (EduFixAssets eduFixAssets1 : eduFixAssetsList) {
                        //判断是否为固定资产
                        if (eduFixAssets1.getIsAssets() != 0) {
                            eduFixAssets1.setIsAssetsStr("是");
                        } else {
                            eduFixAssets1.setIsAssetsStr("否");
                        }
                        //判断是否有证书
                        if (eduFixAssets1.getIsCertificate() != 0) {
                            eduFixAssets1.setIsCertificateStr("是");
                        } else {
                            eduFixAssets1.setIsCertificateStr("否");
                        }
                        //物品状态
                        if (eduFixAssets1.getStatus() != null) {
                            if (eduFixAssets1.getStatus().equals("1")) {
                                eduFixAssets1.setStatus("未使用");
                            } else if (eduFixAssets1.getStatus().equals("2")) {
                                eduFixAssets1.setStatus("使用");
                            } else if (eduFixAssets1.getStatus().equals("3")) {
                                eduFixAssets1.setStatus("损坏");
                            } else if (eduFixAssets1.getStatus().equals("4")) {
                                eduFixAssets1.setStatus("丢失");
                            } else {
                                eduFixAssets1.setStatus("报废");
                            }
                        }
                        //求出资产类型名称
                        if (eduFixAssets1.getTypeId() != 0) {
                            eduFixAssets1.setTypeName(eduFixAssetsMapper.getTypeIdTypeName(String.valueOf(eduFixAssets1.getTypeId())));
                        }
                        //部门名称
                        if (eduFixAssets1.getDeptId() != 0) {
                            String deptId = String.valueOf(eduFixAssets1.getDeptId());
                            eduFixAssets1.setDeptName(eduFixAssetsMapper.getDepartment(deptId));
                        }
                        //求出保管人名称
                        if (eduFixAssets1.getKeeper() != null) {
                            String uid = eduFixAssets1.getKeeper();
                            eduFixAssets1.setKeeper(usersMapper.getUsernameById(uid));
                        }
                        //求出创建人名称
                        if (eduFixAssets1.getCreater() != null) {
                            String uid = eduFixAssets1.getCreater();
                            eduFixAssets1.setCreater(usersMapper.getUsernameById(uid));
                        }
                        //得到资产性质
                        if (!StringUtils.checkNull(eduFixAssets1.getCptlKind())) {
                            if (eduFixAssets1.getCptlKind().equals("01")) {
                                eduFixAssets1.setCptlKindStr("资产");
                            } else if (eduFixAssets1.getCptlKind().equals("02")) {
                                eduFixAssets1.setCptlKindStr("费用");
                            }
                        }
                        //得到增加类型
                        if (!StringUtils.checkNull(eduFixAssets1.getPrcsId())) {
                            if (eduFixAssets1.getPrcsId().equals("1")) {
                                eduFixAssets1.setPrcsIdStr("购入不需安装的固定资产");
                            } else if (eduFixAssets1.getPrcsId().equals("2")) {
                                eduFixAssets1.setCptlKindStr("购入需安装已完工的固定资产");
                            } else if (eduFixAssets1.getPrcsId().equals("3")) {
                                eduFixAssets1.setCptlKindStr("其他单位转入的固定资产(新设备)");
                            } else if (eduFixAssets1.getPrcsId().equals("4")) {
                                eduFixAssets1.setCptlKindStr("其他单位转入的固定资产(旧设备)");
                            } else if (eduFixAssets1.getPrcsId().equals("5")) {
                                eduFixAssets1.setCptlKindStr("捐赠的固定资产");
                            } else if (eduFixAssets1.getPrcsId().equals("6")) {
                                eduFixAssets1.setCptlKindStr("融资租赁的固定资产");
                            } else if (eduFixAssets1.getPrcsId().equals("7")) {
                                eduFixAssets1.setCptlKindStr("固定资产盘盈");
                            }
                        }
                    }
                }

                HSSFWorkbook tableWork = ExcelUtil.makeExcelHead("固定资产信息表", 37);
                String[] secondTitles = {"固定资产编号", "资产名称", "品牌型号", "资产原值", "累计折旧", "资产净值", "月折旧额", "启用日期", "使用年限", "已计提月份", "所在部门", "所在位置", "类别", "残值率", "创建人", "折旧方法", "净残值", "创建时间",
                        "类别编号", "部门编号", "报废日期", "出厂编号", "所在项目", "资产性质", "是否有证书", "证书编号", "增加类型", "折旧年限", "本年计提折旧", "折旧率", "购买时间", "数量", "物品状态", "备注",
                        "有效时间", "减少日期", "条形码", "资产等级", "制造厂商", "出厂日期", "计量单位", "财务编号", "预警数量", "发票号码", "合同号", "设备名称(英文)", "设备代码", "保管人", "是否是固定资产"};
                HSSFWorkbook excelWork = ExcelUtil.makeSecondHead(tableWork, secondTitles);
                String[] beanProperty = {"id", "assetsName", "info", "cptlVal", "sumDpct", "worth", "monDpct", "fromYymm", "useYy", "monAccrual", "deptName", "currutLocation", "typeIdStr", "cptlBal", "createrName", "depreciationMethod", "cptlBalVal", "createrTime",
                        "typeId", "deptId", "logoutTime", "factoryNo", "otherDept", "cptlKindStr", "isCertificateStr", "certificateNo", "prcsIdStr", "dpctYy", "yyDpct", "monDepr", "buyTime", "number", "status", "remake",
                        "validityTime", "dcrDate", "barCode", "capitalLevel", "manuFacturer", "manuDate", "unitId", "fnamark", "alertNum", "invoice", "contractNo", "assetsNameEnglish", "deviceCode", "keeper", "isAssetsStr"};
                HSSFWorkbook workbook = ExcelUtil.exportExcelData(excelWork, eduFixAssetsList, beanProperty);
                OutputStream out = response.getOutputStream();

                String filename = "固定资产信息表.xls"; //考虑多语言
                filename = FileUtils.encodeDownloadFilename(filename, request.getHeader("user-agent"));
                response.setContentType("text/html;charset=UTF-8");
                response.setContentType("application/vnd.ms-excel;charset=UTF-8");
                response.setHeader("content-disposition", "attachment;filename=" + filename);
                workbook.write(out);
                out.flush();
                out.close();
            }
            //用于查询界面显示
            for (EduFixAssets eduFixAssets1 : eduFixAssetsList) {
                //判断非空防止报错
                if (eduFixAssets1.getDeptId() != 0) {
                    String deptId = String.valueOf(eduFixAssets1.getDeptId());
                    eduFixAssets1.setLocationAddressName(eduFixAssetsMapper.getDepartment(deptId));
                }
                //用于获取保管人，admin为特殊，因此特别指出
                if (eduFixAssets1.getKeeper() != null) {
                    String uid = eduFixAssets1.getKeeper();
                    eduFixAssets1.setCustodionName(usersMapper.getUsernameById(uid));
                }
                //用于获取创建者
                if (eduFixAssets1.getCreater() != null) {
                    String uid = eduFixAssets1.getCreater();
                    eduFixAssets1.setCreater(usersMapper.getUsernameById(uid));
                }


            }
            json.setObj(eduFixAssetsList);
            json.setMsg("ok");
            json.setFlag(0);
        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService selFixAssetsByCond:" + e);
            e.printStackTrace();
        }
        return json;
    }


    /**
     * 创建作者:   牛江丽
     * 创建日期:   2017年9月8日 下午16:48:00
     * 方法介绍:   添加固定资产信息
     * 参数说明:   @param eduFixAssets
     * 返回值说明:
     */
    @Transactional
    public synchronized ToJson<EduFixAssets> insertFixAssets(HttpServletRequest request, MultipartFile imageFile, MultipartFile QRcodeFile, EduFixAssets eduFixAssets) {
        ToJson<EduFixAssets> json = new ToJson<EduFixAssets>(1, "error");
        try {
            //图片和二维码的添加，注：必须写在id后
            int imgResult = uploadImg(request, eduFixAssets, imageFile, QRcodeFile);

            if (imgResult != 0) {
                json.setMsg(String.valueOf(imgResult));
                return json;
            }

            eduFixAssets.setSchedulerstatus("1");
            String sessionId = (String) request.getSession().getAttribute(
                    "loginDateSouse");
            eduFixAssets.setCompanyId(sessionId);
            int count = eduFixAssetsMapper.insertFixAssets(eduFixAssets);
            if (count > 0) {
                json.setObject(eduFixAssets);
                json.setMsg("ok");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService insertFixAssets:" + e);
            e.printStackTrace();
        }
        return json;
    }

    /**
     * 创建作者:   牛江丽
     * 创建日期:   2017年9月8日 下午16:48:00
     * 方法介绍:   修改固定资产信息
     * 参数说明:   @param eduFixAssets
     * 返回值说明:
     */
    @Transactional
    public ToJson<EduFixAssets> updateFixAssetsById(HttpServletRequest request, MultipartFile imageFile, MultipartFile QRcodeFile, EduFixAssets eduFixAssets) {
        ToJson<EduFixAssets> json = new ToJson<EduFixAssets>(1, "error");
        try {
            //图片和二维码的添加，注：必须写在id后
            int imgResult = uploadImg(request, eduFixAssets, imageFile, QRcodeFile);
            if (imgResult != 0) {
                json.setMsg(String.valueOf(imgResult));
                return json;
            }
            int count = eduFixAssetsMapper.updateFixAssetsById(eduFixAssets);
            if (count > 0) {
                json.setObject(eduFixAssets);
                json.setMsg("ok");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService updateFixAssetsById:" + e);
            e.printStackTrace();
        }
        return json;
    }

    /**
     * 创建作者:   牛江丽
     * 创建日期:   2017年9月8日 下午17:32:00
     * 方法介绍:   根据id删除固定资产信息
     * 参数说明:   @param id
     * 返回值说明:
     */
    @Transactional
    public ToJson<EduFixAssets> deleteFixAssetsById(String id) {
        ToJson<EduFixAssets> json = new ToJson<EduFixAssets>(1, "error");
        try {
            int count = eduFixAssetsMapper.deleteFixAssetsById(id);
            if (count > 0) {
                json.setMsg("ok");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService deleteFixAssetsById:" + e);
            e.printStackTrace();
        }
        return json;
    }


    /**
     * 创建作者:   牛江丽
     * 创建日期:   2017年9月11日 下午10:02:00
     * 方法介绍:   固定资产导入
     * 参数说明:   @param fixAssetsName 资产名称
     * 返回值说明:
     */
    @Transactional
    public ToJson<EduFixAssets> inputFixAsserts(HttpServletRequest request, HttpServletResponse response, MultipartFile file, HttpSession session) {
        Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users returnuser = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionId);
        ToJson<EduFixAssets> json = new ToJson<EduFixAssets>(1, "error");
        File destFile = null;
        String delFlag = request.getParameter("delFlag");
        InputStream in = null;
        try {
            //判读当前系统
            //读取配置文件
            ResourceBundle rb = ResourceBundle.getBundle("upload");
            //String name = rb.getString("mysql.driverClassName");
            String osName = System.getProperty("os.name");
            StringBuffer path = new StringBuffer();
            StringBuffer buffer = new StringBuffer();
            if (osName.toLowerCase().startsWith("win")) {
                //sb=sb.append(rb.getString("upload.win"));
                //判断路径是否是相对路径，如果是的话，加上运行的路径
                String uploadPath = rb.getString("upload.win");
                if (uploadPath.indexOf(":") == -1) {
                    //获取运行时的路径
                    String basePath = this.getClass().getClassLoader().getResource(".").getPath() + File.pathSeparator;
                    //获取截取后的路径
                    String str2 = "";
                    if (basePath.indexOf("/xoa") != -1) {
                        //获取字符串的长度
                        int length = basePath.length();
                        //返回指定字符在此字符串中第一次出现处的索引
                        int index = basePath.indexOf("/xoa");
                        //从指定位置开始到指定位置结束截取字符串
                        str2 = basePath.substring(0, index);
                    }
                    path = path.append(str2 + "/xoa");
                }
                path.append(uploadPath);
                buffer = buffer.append(rb.getString("upload.win"));
            } else {
                path = path.append(rb.getString("upload.linux"));
                buffer = buffer.append(rb.getString("upload.linux"));
            }
            if (file.isEmpty()) {
                json.setMsg("请上传文件！");
                return json;
            } else {
                String fileName = file.getOriginalFilename();
                if (fileName.endsWith(".xls") || fileName.endsWith(".xlsx")) {
                    String uuid = UUID.randomUUID().toString();
                    uuid = uuid.replaceAll("-", "");
                    int pos = fileName.indexOf(".");
                    String extName = fileName.substring(pos);
                    String newFileName = uuid + extName;
                    File dest = new File(path.toString());
                    if (!dest.exists()) {
                        dest.mkdirs();
                    }
                    destFile = new File(dest, newFileName);
                    if (!destFile.exists()) {
                        destFile.createNewFile();
                    }
                    file.transferTo(destFile);
                    //将文件上传成功后进行读取文件
                    //进行读取的路径
                    String readPath = path.append(System.getProperty("file.separator")).append(newFileName).toString();
                    in = new FileInputStream(readPath);
                    HSSFWorkbook excelObj = new HSSFWorkbook(in);
                    HSSFSheet sheetObj = excelObj.getSheetAt(0);
                    Row rowObj = null;
                    int lastRowNum = sheetObj.getLastRowNum();
                    int inputFail = 0;
                    int inputSuccess = 0;
                    int updateSuccess = 0;
                    String faillReason = "";

                    Map<String, Integer> map = new HashMap<>();
                    map.put("id", 0);           //固定资产编号：
                    map.put("assetsName", 1);//资产名称：
                    map.put("info", 2);//品牌型号：
                    map.put("cptlVal", 3);//资产原值：
                    map.put("sumDpct", 4);//累计折旧：
                    map.put("worth", 5);//资产净值：
                    map.put("monDpct", 6);//月折旧额：
                    map.put("fromYymm", 7);//启用日期：
                    map.put("useYy", 8);//使用年限
                    map.put("monAccrual", 9);//已计提月份：
                    map.put("deptName", 10);            //所在部门：
                    map.put("currutLocation", 11);               //所在位置：
                    map.put("typeIdStr", 12);//类别
                    map.put("cptlBal", 13);//残值率：
                    map.put("creater", 14);//创建人：
                    map.put("depreciationMethod", 15);//折旧方法：
                    map.put("cptlBalVal", 16); //净残值
                    map.put("createrTime", 17);//创建时间：
                    //map.put("typeId",18);// 类别编号
                    //map.put("deptId",19);//部门编号
                    map.put("rescueType", 20);//报废日期：
                    map.put("logoutTime", 21);//是否是应急资源
                    map.put("factoryNo", 22);  //出厂编号：
                    map.put("otherDept", 23);//所在项目：
                    map.put("cptlKindStr", 24);         //资产性质：
                    map.put("isCertificateStr", 25);//是否有证书
                    map.put("certificateNo", 26);   //证书编号：
                    map.put("prcsIdStr", 27); //增加类型：
                    map.put("dpctYy", 28);//折旧年限：
                    map.put("yyDpct", 29);//本年计提折旧：
                    map.put("monDepr", 30);//折旧率：
                    map.put("buyTime", 31); //购买时间：
                    map.put("number", 32);//数量：
                    map.put("status", 33);//物品状态：
                    map.put("remake", 34);//备注：
                    map.put("validityTime", 35);//有效时间：
                    map.put("dcrDate", 36);//减少日期：
                    map.put("barCode", 37);//条形码：
                    map.put("capitalLevel", 38);//资产等级：
                    map.put("manuFacturer", 39);//制造厂商：
                    map.put("manuDate", 40);//出厂日期：
                    map.put("unitId", 41); //计量单位：
                    map.put("fnamark", 42);//财务编号：
                    map.put("alertNum", 43);//预警数量：
                    map.put("invoice", 44);//发票号码：
                    map.put("contractNo", 45);//合同号：
                    map.put("assetsNameEnglish", 46);//设备名称(英文)：
                    map.put("deviceCode", 47);//设备代码：
                    map.put("keeper", 48);//保管人
                    map.put("isAssetsStr", 49); //是否资产


                    Row row = sheetObj.getRow(0);
                    Map<String, Object> notDelMap = new HashMap<String, Object>();
                    for (int i = 2; i <= lastRowNum; i++) {
                        row = sheetObj.getRow(i);
                        if (row != null) {
//                            Cell cell = row.getCell(1);
                            //避免读取空数据
                            EduFixAssets eduFixAssets = ExcelUtil.setCellInfoToModel(row, EduFixAssets.class, new EduFixAssets(), map);
                            if (eduFixAssets.getId() != null && !eduFixAssets.getId().equals(null) && !eduFixAssets.getId().contains("合计")) {
                                //是否固定资产及是否有证书
                                if (eduFixAssets.getIsAssetsStr() != null && eduFixAssets.getIsAssetsStr().equals("是")) {
                                    eduFixAssets.setIsAssets(1);
                                } else {
                                    eduFixAssets.setIsAssets(0);
                                }
                                if (eduFixAssets.getIsCertificateStr() != null && eduFixAssets.getIsCertificateStr().equals("是")) {
                                    eduFixAssets.setIsCertificate(1);
                                } else {
                                    eduFixAssets.setIsCertificate(0);
                                }

                                // 通过部门名称得到部门ID
                                if (!StringUtils.checkNull(eduFixAssets.getDeptName())) {
                                    String DeptName = eduFixAssets.getDeptName();
                                    Department department = new Department();
                                    if (DeptName.contains("/")) {
                                        String[] param = DeptName.split("/");
                                        department.setDeptName(param[0]);
                                        department.setTelNo(param[1]);
                                    } else {
                                        department.setDeptName(DeptName);
                                    }
                                    String deptNameId = departmentMapper.getDeptNameId(department);
                                    if (deptNameId != null) {
                                        eduFixAssets.setDeptId(Integer.valueOf(deptNameId));
                                    }
                                }
                                //通过资产类型名称得到资产类别ID
                                List<String> typeNameTypeId = eduFixAssetsMapper.getTypeNameTypeId(eduFixAssets.getTypeIdStr());
                                if (!StringUtils.checkNull(eduFixAssets.getTypeIdStr()) && typeNameTypeId != null && typeNameTypeId.size() > 0 && !StringUtils.checkNull(typeNameTypeId.get(0))) {
                                    eduFixAssets.setTypeId(Integer.valueOf(typeNameTypeId.get(0)));
                                } else {
                                    eduFixAssets.setTypeId(1);
                                }
                                //通过保管人名称得到保管人ID
                                if (!StringUtils.checkNull(eduFixAssets.getKeeper())) {
                                    String keeper = eduFixAssets.getKeeper();
                                    Users user = new Users();
                                    if (keeper.contains("/")) {
                                        String[] param = keeper.split("/");
                                        user.setUserName(param[0]);
                                        user.setUserId(param[1]);
                                    } else {
                                        user.setUserName(keeper);
                                    }
                                    String userNameId = usersMapper.getUserNameId(user);
                                    if (userNameId != null) {
                                        eduFixAssets.setKeeper(userNameId);
                                    }
                                }
                                //  通过创建者名称得到创建人ID
                                if (!StringUtils.checkNull(eduFixAssets.getCreater())) {
                                    String creater = eduFixAssets.getCreater();
                                    Users user = new Users();
                                    if (creater.contains("/")) {
                                        String[] param = creater.split("/");
                                        user.setUserName(param[0]);
                                        user.setUserId(param[1]);
                                    } else {
                                        user.setUserName(creater);
                                    }
                                    String userNameId = usersMapper.getUserNameId(user);
                                    if (userNameId != null) {
                                        eduFixAssets.setCreater(userNameId);
                                    } else {
                                        eduFixAssets.setCreater("1");
                                    }
                                }
                                //物品状态
                                if (eduFixAssets.getStatus() != null) {
                                    if (eduFixAssets.getStatus().equals("未使用")) {
                                        eduFixAssets.setStatus("1");
                                    } else if (eduFixAssets.getStatus().equals("使用")) {
                                        eduFixAssets.setStatus("2");
                                    } else if (eduFixAssets.getStatus().equals("损坏")) {
                                        eduFixAssets.setStatus("3");
                                    } else if (eduFixAssets.getStatus().equals("丢失")) {
                                        eduFixAssets.setStatus("4");
                                    } else {
                                        eduFixAssets.setStatus("5");
                                    }
                                }
                                //目前所在位置
                                if (eduFixAssets.getCurrutLocation() != null) {
                                    SysCode sysCode = new SysCode();
                                    sysCode.setCodeName(eduFixAssets.getCurrutLocation());
                                    sysCode.setParentNo("LOCATION_ADDRESS");
                                    SysCode sysCode1 = sysCodeMapper.getCodeNoByNameAndParentNo(sysCode);
                                    if (sysCode1 != null) {
                                        eduFixAssets.setCurrutLocation(String.valueOf(sysCode1.getCodeNo()));
                                    } else {
                                        String maxCodeNo = sysCodeMapper.selectMaxNoCode("LOCATION_ADDRESS");
                                        sysCode.setCodeNo(String.valueOf(Integer.valueOf(maxCodeNo) + 1));
                                        sysCode.setCodeOrder("999");
                                        sysCode.setCodeExt("");
                                        sysCode.setCodeFlag("1");
                                        sysCode.setIsCan("1");
                                        sysCode.setIsRemind("1");
                                        sysCode.setIsIphone("1");
                                        sysCodeMapper.addSysChildCode(sysCode);
                                        eduFixAssets.setCurrutLocation(String.valueOf(sysCode.getCodeNo()));
                                    }

                                }
                                //是否是固定资产
                                if (eduFixAssets.getIsAssetsStr() != null) {
                                    if ("否".equals(eduFixAssets.getIsAssetsStr())) {
                                        eduFixAssets.setIsAssets(0);
                                    } else {
                                        eduFixAssets.setIsAssets(1);
                                    }
                                } else {
                                    eduFixAssets.setIsAssets(1);
                                }
                                //类别
                                /*if(eduFixAssets.getTypeIdStr()!=null && !"".equals(eduFixAssets.getTypeIdStr())){
                                    List<String> typeid=eduFixAssetsMapper.getTypeNameTypeId(eduFixAssets.getTypeIdStr());
                                    if(typeid!=null&&typeid.size()>0&&StringUtils.checkNull(typeid.get(0))) {
                                        eduFixAssets.setTypeId(Integer.parseInt(typeid.get(0)));
                                    }
                                }*/
                                //所在部门
                                if (eduFixAssets.getDeptName() != null && !"".equals(eduFixAssets.getDeptName())) {
                                    List<String> deptId = departmentMapper.getDeptIdByDeptName(eduFixAssets.getDeptName());
                                    if (deptId.size() > 0) {
                                        eduFixAssets.setDeptId(Integer.parseInt(deptId.get(0)));
                                    }

                                }
                                //所在项目
                                if (eduFixAssets.getOtherDept() != null && !"".equals(eduFixAssets.getOtherDept())) {
                                    List<CrashDispatch> list = crashDispatchMapper.selectByEventName(eduFixAssets.getOtherDept());
                                    if (list != null && list.size() >= 1) {
                                        eduFixAssets.setProjectName(String.valueOf(list.get(0).getCrasId()));
                                    }
                                }
                                //资产性质
                                if (eduFixAssets.getCptlKindStr() != null && !"".equals(eduFixAssets.getCptlKindStr())) {
                                    if ("资产".equals(eduFixAssets.getCptlKindStr())) {
                                        eduFixAssets.setCptlKind("01");
                                    } else if ("费用".equals(eduFixAssets.getCptlKindStr())) {
                                        eduFixAssets.setCptlKind("02");
                                    }
                                }
                                //是否有证书
                                if (eduFixAssets.getIsCertificateStr() != null && !"".equals(eduFixAssets.getIsCertificateStr())) {
                                    if ("没有".equals(eduFixAssets.getIsCertificateStr())) {
                                        eduFixAssets.setIsCertificate(0);
                                    } else {
                                        eduFixAssets.setIsCertificate(1);
                                    }
                                }
                                //增加类型
                                if (eduFixAssets.getPrcsIdStr() != null && !"".equals(eduFixAssets.getPrcsIdStr())) {
                                    if ("购入不需安装的固定资产".equals(eduFixAssets.getPrcsIdStr())) {
                                        eduFixAssets.setPrcsId("1");
                                    } else if ("购入需安装已完工的固定资产".equals(eduFixAssets.getPrcsIdStr())) {
                                        eduFixAssets.setPrcsId("2");
                                    } else if ("购入需安装已完工的固定资产".equals(eduFixAssets.getPrcsIdStr())) {
                                        eduFixAssets.setPrcsId("2");
                                    } else if ("其他单位转入的固定资产(新设备)".equals(eduFixAssets.getPrcsIdStr())) {
                                        eduFixAssets.setPrcsId("3");
                                    } else if ("其他单位转入的固定资产(旧设备)".equals(eduFixAssets.getPrcsIdStr())) {
                                        eduFixAssets.setPrcsId("4");
                                    } else if ("捐赠的固定资产".equals(eduFixAssets.getPrcsIdStr())) {
                                        eduFixAssets.setPrcsId("5");
                                    } else if ("融资租赁的固定资产".equals(eduFixAssets.getPrcsIdStr())) {
                                        eduFixAssets.setPrcsId("6");
                                    } else if ("固定资产盘盈".equals(eduFixAssets.getPrcsIdStr())) {
                                        eduFixAssets.setPrcsId("7");
                                    }
                                }
                                //创建人
                               /* if(eduFixAssets.getCreaterName()!=null &&"".equals(eduFixAssets.getCreaterName())){
                                    Users u=usersMapper.getUserByName(eduFixAssets.getCreaterName());
                                    if(u!=null){
                                        eduFixAssets.setCreater(u.getUid().toString());
                                    }
                                }else{
                                    eduFixAssets.setCreater(returnuser.getUid().toString());
                                }*/

                                if (!StringUtils.checkNull(eduFixAssets.getCreaterName())) {
                                    eduFixAssets.setCreater(eduFixAssets.getCreaterName());
                                }
                                //创建时间
                                if (eduFixAssets.getCreaterTime() != null || !"".equals(eduFixAssets.getCreaterTime())) {
                                    eduFixAssets.setCreaterTime(eduFixAssets.getCreaterTime());
                                }
                                eduFixAssets.setDcrDate("");

                                // 购买时间
                                if (StringUtils.checkNull(eduFixAssets.getBuyTime())) {
                                    eduFixAssets.setBuyTime(eduFixAssets.getFromYymm());
                                }

                                //启用时间
                                if (!StringUtils.checkNull(eduFixAssets.getFromYymm())) {
                                    eduFixAssets.setFromYymm(eduFixAssets.getFromYymm());
                                }
                                if (eduFixAssetsMapper.selFixAssetsById(eduFixAssets.getId()) == null) {
                                    //添加数据
                                    eduFixAssetsMapper.insertEduFixAssetsExcel(eduFixAssets);
                                    notDelMap.put(eduFixAssets.getId(), "1");
                                    inputSuccess++;
                                    continue;
                                } else {
                                    //更新数据
                                    eduFixAssetsMapper.updateByAssets(eduFixAssets);
                                    notDelMap.put(eduFixAssets.getId(), "1");
                                    updateSuccess++;
                                    continue;
                                }
                            }
                        }
                    }
                    // 删除导入表以外的数据
                    // ------ 删除开始 ----------
                    if (!StringUtils.checkNull(delFlag) && "1".equals(delFlag)) {
                        List<String> strings = eduFixAssetsMapper.selAllFixAssetsId();
                        Iterator<String> iterator = strings.iterator();
                        while (iterator.hasNext()) {
                            if (notDelMap.get(iterator.next()) != null) {
                                iterator.remove();
                            }
                        }
                        // 重新初始化
                        iterator = strings.iterator();
                        // 遍历执行删除操作
                        while (iterator.hasNext()) {
                            eduFixAssetsMapper.deleteFixAssetsById(iterator.next());
                        }
                    }
                    // ------ 删除结束 -----------

                    EduFixAssets temp = new EduFixAssets();
                    temp.setInputFail(inputFail);
                    temp.setInputSuccess(inputSuccess);
                    temp.setUpdateSuccess(updateSuccess);
                    temp.setInputFailReason(faillReason);
                    destFile.delete();
                    json.setObject(temp);
                    json.setFlag(0);
                    json.setMsg("ok");
                    //dest.delete();
                } else {
                    json.setMsg("0");//文件类型不正确
                    return json;
                }
            }
        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService inputFixAsserts:" + e);
            e.printStackTrace();
        } finally {
            destFile.delete();
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return json;
    }


    /**
     * 创建作者:   牛江丽
     * 创建日期:   2017年9月11日 下午14:18:00
     * 方法介绍:   根据id进行查询固定资产
     * 参数说明:   @param id 资产id
     * 返回值说明:
     */
    public ToJson<Object> selFixAssetsById(HttpServletRequest request, String id) {
        ToJson<Object> json = new ToJson<Object>(1, "error");
        try {
            String sqlType = "xoa" + (String) request.getSession().getAttribute("loginDateSouse");
            EduFixAssets eduFixAssets = eduFixAssetsMapper.selFixAssetsById(id);

            //得到资产性质
            if (!StringUtils.checkNull(eduFixAssets.getCptlKind())) {
                if (eduFixAssets.getCptlKind().equals("01")) {
                    eduFixAssets.setCptlKindStr("资产");
                } else if (eduFixAssets.getCptlKind().equals("02")) {
                    eduFixAssets.setCptlKindStr("费用");
                }
            }
            if(!StringUtils.checkNull(eduFixAssets.getScheduler())){
                String usernameByUserId = usersMapper.getUsernameByUserId(eduFixAssets.getScheduler().substring(0,eduFixAssets.getScheduler().length() -1));
                eduFixAssets.setSchedulerName(usernameByUserId);
            }
            //得到增加类型
            if (!StringUtils.checkNull(eduFixAssets.getPrcsId())) {
                if (eduFixAssets.getPrcsId().equals("1")) {
                    eduFixAssets.setPrcsIdStr("购入不需安装的固定资产");
                } else if (eduFixAssets.getPrcsId().equals("2")) {
                    eduFixAssets.setCptlKindStr("购入需安装已完工的固定资产");
                } else if (eduFixAssets.getPrcsId().equals("3")) {
                    eduFixAssets.setCptlKindStr("其他单位转入的固定资产(新设备)");
                } else if (eduFixAssets.getPrcsId().equals("4")) {
                    eduFixAssets.setCptlKindStr("其他单位转入的固定资产(旧设备)");
                } else if (eduFixAssets.getPrcsId().equals("5")) {
                    eduFixAssets.setCptlKindStr("捐赠的固定资产");
                } else if (eduFixAssets.getPrcsId().equals("6")) {
                    eduFixAssets.setCptlKindStr("融资租赁的固定资产");
                } else if (eduFixAssets.getPrcsId().equals("7")) {
                    eduFixAssets.setCptlKindStr("固定资产盘盈");
                }
            }
            //得到保管人
            if (!StringUtils.checkNull(eduFixAssets.getKeeper())) {
                if (eduFixAssets.getKeeper() != null) {
                    eduFixAssets.setKeeperName(usersMapper.getUsernameById(eduFixAssets.getKeeper()));
                }
            }
            //得到创建人
            if (!StringUtils.checkNull(eduFixAssets.getCreater())) {
                if (eduFixAssets.getCreater() != null) {
                    eduFixAssets.setCreaterName(usersMapper.getUsernameById(eduFixAssets.getCreater()));
                }
            }
            //得到所在部门
            if ((eduFixAssets.getDeptId() != 0)) {
                String deptId = String.valueOf(eduFixAssets.getDeptId());
                eduFixAssets.setDeptName(eduFixAssetsMapper.getDepartment(deptId));
            }
            //根据资产类别ID 得到资产类别名称
            if ((eduFixAssets.getTypeId() != 0)) {
                eduFixAssets.setTypeName(eduFixAssetsMapper.getTypeIdTypeName(String.valueOf(eduFixAssets.getTypeId())));
            }
            List<Attachment> attachments = GetAttachmentListUtil.returnAttachment(eduFixAssets.getAttachmentName(), eduFixAssets.getAttachmentId(), sqlType, GetAttachmentListUtil.MODULE_ASSET);
            if (attachments != null && attachments.size() > 0) {
                eduFixAssets.setAttachmentList(attachments);
            }
            String currutLocation = eduFixAssets.getCurrutLocation();
            if (!StringUtils.checkNull(currutLocation)) {
                SysCode SysCode = sysCodeMapper.getSingleCode("LOCATION_ADDRESS", currutLocation);
                if (SysCode != null) {
                    eduFixAssets.setCustodionName(SysCode.getCodeName());
                }
            }
//            if(!StringUtils.checkNull(eduFixAssets.getCurrutLocation())){
//                if(departmentMapper.getDeptById(Integer.parseInt(eduFixAssets.getCurrutLocation()))!=null){
//                    eduFixAssets.setLocationAddressName(departmentMapper.getDeptById(Integer.parseInt(eduFixAssets.getCurrutLocation())).getDeptName());
//                }
//            }
            json.setObject(eduFixAssets);
            json.setMsg("ok");
            json.setFlag(0);
        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService selFixAssetsById:" + e);
            e.printStackTrace();
        }
        return json;
    }

    /**
     * 图片上传
     *
     * @param request
     * @param imageFile
     */
    public int uploadImg(HttpServletRequest request, EduFixAssets eduFixAssets, MultipartFile imageFile, MultipartFile QRcodeFile) {
        int resultFlag = 0;
        try {
            //图片进行处理
            if (imageFile != null) {
                String imageType = imageFile.getContentType();
                boolean b = allowUpload(imageType);
                if (!b) {
                    resultFlag = 1;//固定资源图片格式不正确
                }
            }
            if (QRcodeFile != null) {
                String QRcodeType = QRcodeFile.getContentType();
                boolean b = allowUpload(QRcodeType);
                if (!b) {
                    resultFlag = 2;//二维码格式不正确
                }
            }
            String realPath = request.getSession().getServletContext().getRealPath("/");

            String resourcePath = "ui/img/edu/eduFixAssets";
            //先查询是否已经上传了该图片，如果上传了删除后再上传，否则直接上传
            EduFixAssets temp = eduFixAssetsMapper.selFixAssetsById(eduFixAssets.getId());
            if (temp != null) {
                if (!StringUtils.checkNull(temp.getImage())) {//固定资产图片
                    File temp1 = new File(realPath + resourcePath + temp.getImage());
                    if (temp1.exists()) {
                        temp1.delete();
                    }
                }
                if (!StringUtils.checkNull(temp.getQrCode())) {//二维码图片
                    File temp2 = new File(realPath + resourcePath + temp.getQrCode());
                    if (temp2.exists()) {
                        temp2.delete();
                    }
                }
            }
            //上传图片并进行修改数据库数据
            if (imageFile != null) {
                if (allowUpload(imageFile.getContentType())) {
                    String fileName = FileUploadUtil.rename(imageFile.getOriginalFilename());
                    File dir = new File(realPath + resourcePath);
                    if (!dir.exists()) {
                        dir.mkdirs();
                    }
                    File file = new File(dir, fileName);
                    imageFile.transferTo(file);
                    eduFixAssets.setImage(fileName);
                }
            }
            if (QRcodeFile != null) {
                if (allowUpload(QRcodeFile.getContentType())) {
                    String fileName = FileUploadUtil.rename(QRcodeFile.getOriginalFilename());
                    File dir = new File(realPath + resourcePath);
                    // File dir = new File(temp.getId ());
                    if (!dir.exists()) {
                        dir.mkdirs();
                    }
                    File file = new File(dir, fileName);
                    QRcodeFile.transferTo(file);
                    eduFixAssets.setQrCode(fileName);
                }
            }
        } catch (Exception e) {
            L.e("EduFixAssetsService selFixAssetsById:" + e);
            e.printStackTrace();
        }
        return resultFlag;
    }

    /**
     * 创建作者:   牛江丽
     * 创建日期:   2017年9月11日 下午14:18:00
     * 方法介绍:   添加时获取id
     * 参数说明:   @param id 资产id
     * 返回值说明:
     */
    public ToJson<EduFixAssets> getFixAssetsId() {
        ToJson<EduFixAssets> json = new ToJson<EduFixAssets>(1, "error");
        try {
            String idStr = "GDZC" + DateFormat.getDatestr(new Date());
            String s = idStr.replaceAll("-", "");
            String maxId = eduFixAssetsMapper.selectMaxId(s);
            String OriginId = "00001";
            if (!StringUtils.checkNull(maxId)) {
                String tempId = String.valueOf(Integer.valueOf(maxId.substring(12, maxId.length())) + 1);
                String zeroStr = "";
                for (int i = tempId.length(); i < 6 - tempId.length(); i++) {
                    zeroStr += "0";
                }
                OriginId = zeroStr + tempId;
            }
            String IdStr = "GDZC" + DateFormat.getDatestr(new Date()) + OriginId;
            EduFixAssets eduFixAssets = new EduFixAssets();
            eduFixAssets.setId(IdStr.replaceAll("-", ""));
            SimpleDateFormat sdf = new SimpleDateFormat("YYYY-mm-dd");
            Date date = new Date();
            eduFixAssets.setCreaterTime(DateFormat.getDatestr(new Date()));
            json.setMsg("ok");
            json.setObject(eduFixAssets);
            json.setFlag(0);
        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService getFixAssetsId:" + e);
            e.printStackTrace();
        }
        return json;
    }

    /**
     * 创建作者:  陈玲
     * 创建日期:   2018年7月20日
     * 方法介绍:   固定资产信息企业id及信息
     * 参数说明:   @param EduFixAssets
     * 返回值说明:
     */
    @Transactional
    public ToJson<EduFixAssets> getFixAssetsAll(EduFixAssets eduFixAssets) {
        //取全部固定资产中的id,企业id 及二维码
        ToJson<EduFixAssets> json = new ToJson<EduFixAssets>(1, "error");
        List<Object> assets = new ArrayList<>();
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("EduFixAssets", eduFixAssets);
            List<EduFixAssets> edulsit = eduFixAssetsMapper.selFixAssetsAll(map);
            for (EduFixAssets list : edulsit) {
                EduFix fixAssets = new EduFix();
                fixAssets.setQrCode(list.getQrCode());
                fixAssets.setId(list.getId());
                fixAssets.setCompanyId(list.getCompanyId());
                fixAssets.setCreaterTime(list.getCreaterTime());
                fixAssets.setAssetsName(list.getAssetsName());
                assets.add(fixAssets);
            }

            if (assets != null) {
                json.setObject(assets);
                json.setMsg("true");
                json.setFlag(0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }


    public ToJson<EduFixAssetsType> getFixAssetstypeName() {
        ToJson<EduFixAssetsType> json = new ToJson<EduFixAssetsType>(1, "error");
        try {
            List<EduFixAssetsType> eduFixAssetsTypes = eduFixAssetsMapper.getFixAssetstypeName();
            if (eduFixAssetsTypes.size() > 0) {
                json.setMsg("ok");
                json.setObject(eduFixAssetsTypes);
                json.setFlag(0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }

    public ToJson<FlowFast> addGoToFixAssets(String userid, String createTime, String type, HttpServletRequest request) {
        ToJson<FlowFast> flowFastToJson = new ToJson<>();
        Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionId);
        String sqlType = "xoa" + (String) request.getSession().getAttribute(
                "loginDateSouse");
        FlowTypeModel ftm = flowTypeModelMapper.getFlowByName(type);
        flowFastToJson = wfeFlowRunInfo.workFastAdd(user, ftm.getFlowId(), 1, "1", "", request, sqlType, "", null);
        return flowFastToJson;
    }

    public ToJson<EduFixAssets> selectEduFixAssets(HttpServletRequest request, String assetsName, Integer isAssets, String deptId, String currrntLocation, Integer page, Integer pageSize, Boolean useFlag, String scheduler, String assetsId) {
        ToJson<EduFixAssets> toJson = new ToJson();
        Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionId);
        try {
            Map<String, Object> map = new HashMap();
            Integer pageNumber = 0;
            Integer totalNum = 0;
            if (page != null && !"".equals(page)) {
                pageNumber = (page - 1) * pageSize;
            }
            PageParams pageParams = new PageParams();
            pageParams.setPage(page);
            pageParams.setPageSize(pageSize);
            pageParams.setUseFlag(useFlag);
            map.put("page", pageParams);
            map.put("assetsName", assetsName);
            map.put("isAssets", isAssets);
            map.put("currrntLocation", currrntLocation);
            map.put("assetsId", assetsId);
            if (scheduler != null && !"".equals(scheduler)) {
                map.put("scheduler", user.getUserId());
                map.put("schedulerStatus", "1");
            }
            if (deptId != null && !"".equals(deptId)) {
                if (!"0".equals(deptId) && !"ALL_DEPT".equals(deptId)) {
                    String[] deptIdStr = deptId.split(",");
                    map.put("deptId", deptIdStr);
                }
            }

            List<EduFixAssets> eduFixAssets = eduFixAssetsMapper.selectEduFixAssets(map);
            for (EduFixAssets fixAssets : eduFixAssets) {
                int deptId1 = fixAssets.getDeptId();
                if (deptId1 > 0) {
                    String deptNameById = departmentMapper.getDeptNameById(deptId1);
                    fixAssets.setDeptName(deptNameById);
                }
                if(!StringUtils.checkNull(fixAssets.getScheduler())){
                    String usernameByUserId = usersMapper.getUsernameByUserId(fixAssets.getScheduler().substring(0,fixAssets.getScheduler().length() -1));
                    fixAssets.setSchedulerName(usernameByUserId);
                }

                //所属项目
                String otherDept = fixAssets.getOtherDept();
                if (otherDept != null && !"".equals(otherDept) && !"0.00".equals(otherDept)) {
                    CrashDispatchWithBLOBs crashDispatchWithBLOBs = crashDispatchMapper.selectByCrasId(Integer.valueOf(otherDept));
//                    String codeName = sysCodeMapper.getCodeName(Integer.parseInt(otherDept));
                    if (crashDispatchWithBLOBs != null) {
                        fixAssets.setProjectName(crashDispatchWithBLOBs.getPareEventName() + "-" + crashDispatchWithBLOBs.getEventName());
                    }
                }
                int typeId = fixAssets.getTypeId();
                String s = String.valueOf(typeId);
                String typeIdTypeName = eduFixAssetsMapper.getTypeIdTypeName(s);
                fixAssets.setTypeName(typeIdTypeName);
                //目前所在位置
                String currutLocation = fixAssets.getCurrutLocation();
                if (currutLocation != null && !"".equals(currutLocation) && !"0".equals(currutLocation)) {
                    SysCode sysCode = sysCodeMapper.getSingleCode("LOCATION_ADDRESS", currutLocation);
                    if (sysCode != null) {
                        fixAssets.setCurrutLocation(sysCode.getCodeName());
                    }
                }
            }
            // totalNum = eduFixAssetsMapper.selectEduFixAssetsTotal(map);
            toJson.setFlag(0);
            toJson.setObj(eduFixAssets);
            toJson.setTotleNum(pageParams.getTotal());
        } catch (Exception e) {
            toJson.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return toJson;
    }

    public ToJson getCurrrntLocation() {
        ToJson toJson = new ToJson();
        try {
            List<String> currrntLocation = eduFixAssetsMapper.getCurrrntLocation();
            toJson.setFlag(0);
            toJson.setObj(currrntLocation);
        } catch (Exception e) {
            toJson.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return toJson;
    }

    public ToJson<List<Map<String, Object>>> eduFixAssetsStatistical(String projectId, String currrntLocation) {
        ToJson<List<Map<String, Object>>> toJson = new ToJson();
        try {
            Map<String, Object> map = new HashMap<>();
            map.put("otherDept", projectId);
            map.put("currrntLocation", currrntLocation);
            List<Map<String, Object>> list = new ArrayList<>();
            List listObj = new ArrayList();
            //项目名称
            List<SysCode> projectNameSysCode = sysCodeMapper.getSysCode("PROJECT_NAME");
            //所在位置
            List<SysCode> locationAddress = sysCodeMapper.getSysCode("LOCATION_ADDRESS");
            //List<String> currrntLocations = eduFixAssetsMapper.getCurrrntLocation();
            //类型
            List<EduFixAssetsType> fixAssetsTypeName = eduFixAssetsMapper.getFixAssetstypeName();
            //所属部门
            List<Department> allDepartment = departmentMapper.getAllDepartment();
            //项目名称
            if ("".equals(projectId) || projectId == null) {
                Integer projectNameSysCode1 = selectProjectName(list, projectNameSysCode, map, "otherDept");
                listObj.add("项目总固资数：" + projectNameSysCode1);
            }
            //所属部门
            Integer allDepartment1 = selectDeptId(list, allDepartment, map, "deptId");
            listObj.add("部门总固资数：" + allDepartment1);
            //类型
            Integer fixAssetsTypeName1 = selectFixAssetsType(list, fixAssetsTypeName, map, "typeId");
            listObj.add("类型总固资数：" + fixAssetsTypeName1);
            //所在位置
            if ("".equals(currrntLocation) || currrntLocation == null) {
                Integer currrntLocation1 = selectProjectName(list, locationAddress, map, "currrntLocation");
                listObj.add("位置总固资数：" + currrntLocation1);
            }
            /*if ("".equals(currrntLocation)||currrntLocation==null) {
                Integer currrntLocation1 = selectCurrrntLocation(list, currrntLocations, map, "currrntLocation");
                listObj.add("位置总固资数：" + currrntLocation1);
            }*/
            toJson.setFlag(0);
            toJson.setObject(list);
            toJson.setObj(listObj);
        } catch (Exception e) {
            toJson.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return toJson;
    }

    public Integer selectProjectName(List<Map<String, Object>> list, List<SysCode> sysCodes, Map map, String s) {
        Integer number = 0;
        Map<String, Object> maps = new HashMap<>();
        for (SysCode sysCode : sysCodes) {
            Integer codeId = sysCode.getCodeId();
            String codeIds = sysCode.getCodeNo();
            String codeName = sysCode.getCodeName();
            map.put(s, codeIds);
            Integer i = eduFixAssetsMapper.eduFixAssetsStatistical(map);
            number += i;
            if (i > 0) {
                maps.put(codeName, i);
            }
            map.remove(s);
        }
        list.add(maps);
        return number;
    }

    public Integer selectDeptId(List<Map<String, Object>> list, List<Department> departments, Map map, String s) {
        Integer number = 0;
        Map<String, Object> maps = new HashMap<>();
        for (Department department : departments) {
            Integer deptId = department.getDeptId();
            String deptName = department.getDeptName();
            map.put(s, deptId);
            Integer i = eduFixAssetsMapper.eduFixAssetsStatistical(map);
            number += i;
            if (i > 0) {
                if (deptId == 0) {
                    maps.put("无部门", i);
                } else {
                    maps.put(deptName, i);
                }
            }
            map.remove(s);
        }
        list.add(maps);
        return number;
    }

    public Integer selectFixAssetsType(List<Map<String, Object>> list, List<EduFixAssetsType> eduFixAssetsTypes, Map map, String s) {
        Integer number = 0;
        Map<String, Object> maps = new HashMap<>();
        for (EduFixAssetsType eduFixAssetsType : eduFixAssetsTypes) {
            String typeId = eduFixAssetsType.getTypeId();
            String typeName = eduFixAssetsType.getTypeName();
            map.put(s, Integer.parseInt(typeId));
            Integer i = eduFixAssetsMapper.eduFixAssetsStatistical(map);
            number += i;
            if (i > 0) {
                maps.put(typeName, i);
            }
            map.remove(s);
        }
        list.add(maps);
        return number;
    }

    public Integer selectCurrrntLocation(List<Map<String, Object>> list, List<String> strings, Map map, String s) {
        Integer number = 0;
        Map<String, Object> maps = new HashMap<>();
        for (String string : strings) {
            map.put(s, string);
            Integer i = eduFixAssetsMapper.eduFixAssetsStatistical(map);
            number += i;
            if (i > 0) {
                maps.put(string, i);
            }
            map.remove(s);
        }
        list.add(maps);
        return number;
    }

    public ToJson updateEduFixAssets(String id, Integer typeId, String deptId, String currutLocation, String status, String otherDept) {
        ToJson toJson = new ToJson();
        try {
            boolean contains = id.contains(",");
            Integer num = 0;
            if (contains) {
                String[] split = id.split(",");
                for (int i = 0; i < split.length; i++) {
                    String s = split[i];
                    if (s != null && !"".equals(s)) {
                        EduFixAssets eduFixAssets = new EduFixAssets();
                        eduFixAssets.setId(s);
                        if (typeId != null) {
                            eduFixAssets.setTypeId(typeId);
                        }
                        if (deptId != null && !"".equals(deptId)) {
                            String substring = deptId.substring(0, deptId.indexOf(","));
                            eduFixAssets.setDeptId(Integer.parseInt(substring));
                        }
                        eduFixAssets.setCurrutLocation(currutLocation);
                        eduFixAssets.setStatus(status);
                        eduFixAssets.setOtherDept(otherDept);
                        num = eduFixAssetsMapper.updateById(eduFixAssets);
                    }
                }
                if (num > 0) {
                    toJson.setFlag(0);
                    toJson.setMsg(num.toString());
                }
            }
        } catch (Exception e) {
            toJson.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return toJson;
    }

    public ToJson updateEduFixAssetsModifyById(String id, Integer typeId, String deptId, String currutLocation, String status, String otherDept, String scheduler) {
        ToJson toJson = new ToJson();
        try {
            boolean contains = id.contains(",");
            Integer num = 0;
            if (contains) {
                String[] split = id.split(",");
                for (int i = 0; i < split.length; i++) {
                    String s = split[i];
                    if (s != null && !"".equals(s)) {
                        EduFixAssets eduFixAssets = new EduFixAssets();
                        eduFixAssets.setId(s);
                        if (typeId != null) {
                            eduFixAssets.setTypeId(typeId);
                        }
                        if (deptId != null && !"".equals(deptId)) {
                            String substring = deptId.substring(0, deptId.indexOf(","));
                            eduFixAssets.setDeptId(Integer.parseInt(substring));
                        }
                        eduFixAssets.setCurrutLocation(currutLocation);
                        eduFixAssets.setStatus(status);
                        eduFixAssets.setOtherDept(otherDept);
                        eduFixAssets.setModifyContent(JSON.toJSONString(eduFixAssets));
                        eduFixAssets.setScheduler(scheduler);
                        eduFixAssets.setSchedulerstatus("");

                        num = eduFixAssetsMapper.updateById(eduFixAssets);
                    }
                }
                if (num > 0) {
                    toJson.setFlag(0);
                    toJson.setMsg("true");
                }
            }
        } catch (Exception e) {
            toJson.setFlag(1);
            toJson.setMsg(e.getMessage());
        }
        return toJson;
    }

    public ToJson selEduFixAssets(String assetsName, Integer typeId, String deptId, String currutLocation, Integer status, String otherDept) {
        ToJson toJson = new ToJson();
        try {
            Map<String, Object> map = new HashMap<>();
            map.put("assetsName", assetsName);
            map.put("typeId", typeId);
            map.put("currrntLocation", currutLocation);
            map.put("status", status);
            map.put("otherDept", otherDept);
            if (deptId.contains(",")) {
                String substring = deptId.substring(0, deptId.indexOf(","));
                map.put("deptId", Integer.parseInt(substring));
            }
            List<EduFixAssets> eduFixAssets = eduFixAssetsMapper.selEduFixAssets(map);
            toJson.setObj(eduFixAssets);
            toJson.setFlag(0);
        } catch (Exception e) {
            toJson.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return toJson;
    }

    public ToJson updateQueren(HttpServletRequest request, String id, String schedulerstatus, String notAcceptReason) {
        ToJson toJson = new ToJson();
        try {
            //确认之后更新数据
            if ("0".equals(schedulerstatus)) {
                EduFixAssets eduFixAssets = eduFixAssetsMapper.selFixAssetsById(id);
                String modifycontent = eduFixAssets.getModifyContent();
                EduFixAssets eduFixAssets1 = JSON.parseObject(modifycontent, EduFixAssets.class);
                eduFixAssets1.setSchedulerstatus(schedulerstatus);
                eduFixAssetsMapper.updateById(eduFixAssets1);
            }
            if ("1".equals(schedulerstatus)) {
                EduFixAssets eduFixAssets = new EduFixAssets();
                eduFixAssets.setId(id);
                eduFixAssets.setSchedulerstatus(schedulerstatus);
                eduFixAssets.setNotAcceptReason(notAcceptReason);
                eduFixAssetsMapper.updateById(eduFixAssets);
            }
            toJson.setMsg("true");
            toJson.setFlag(0);
        } catch (Exception e) {
            toJson.setFlag(1);
            toJson.setMsg(e.getMessage());
        }
        return toJson;
    }

    public ToJson updateQuerenBatch(HttpServletRequest request, String ids) {
        ToJson toJson = new ToJson();
        Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users returnuser = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionId);
        try {
            if (ids == null || "".equals(ids)) {
                Map map = new HashMap();
                map.put("scheduler", returnuser.getUserId());
                List<EduFixAssets> list = eduFixAssetsMapper.selectEduFixAssets(map);
                for (EduFixAssets eduFixAssets : list) {
                    if (eduFixAssets.getSchedulerstatus().equals("1")) {
                        //未确认的进行确认
                        String modifycontent = eduFixAssets.getModifyContent();
                       // EduFixAssets eduFixAssets1 = JSON.parseObject(modifycontent, EduFixAssets.class);
                        eduFixAssets.setSchedulerstatus("0");
                        eduFixAssetsMapper.updateById(eduFixAssets);
                    }
                }
            } else {
                if (ids != null && ids.length() > 0) {
                    String idStr[] = ids.split(",");
                    for (String id : idStr) {
                        //确认之后更新数据
                        EduFixAssets eduFixAssets = eduFixAssetsMapper.selFixAssetsById(id);
                        String modifycontent = eduFixAssets.getModifyContent();
                        EduFixAssets eduFixAssets1 = JSON.parseObject(modifycontent, EduFixAssets.class);
                        eduFixAssets1.setSchedulerstatus("0");
                        eduFixAssetsMapper.updateById(eduFixAssets1);

                    }
                }
            }
            toJson.setMsg("true");
            toJson.setFlag(0);
        } catch (Exception e) {
            toJson.setMsg(e.getMessage());
            toJson.setFlag(1);
        }
        return toJson;
    }

    public ToJson getEdufixAssets(HttpServletRequest request, String id) {
        ToJson toJson = new ToJson();
        try {
            EduFixAssets eduFixAssets = eduFixAssetsMapper.selFixAssetsById(id);
            String modifyContent = eduFixAssets.getModifyContent();
            EduFixAssets eduFixAssets1 = JSON.parseObject(modifyContent, EduFixAssets.class);
            //资产管理名字
            eduFixAssets1.setAssetsName(eduFixAssets.getAssetsName());
            if (eduFixAssets.getDeptId() != 0) {
                int deptId = eduFixAssets.getDeptId();
                String deptName = departmentMapper.getDeptNameByDeptId(deptId);
                eduFixAssets1.setDeptId(deptId);
                eduFixAssets1.setDeptName(deptName);
            }
            if (eduFixAssets.getScheduler() != null && !("").equals(eduFixAssets.getScheduler())) {
                String userid = eduFixAssets.getScheduler();
                String userId = userid.substring(0, userid.length() - 1);
                String userName = usersMapper.getUsernameByUserId(userId);
                eduFixAssets1.setScheduler(userid);
                eduFixAssets1.setSchedulerName(userName);
            }
            toJson.setObject(eduFixAssets1);
            toJson.setFlag(0);
            toJson.setMsg("true");
        } catch (Exception e) {
            toJson.setFlag(1);
            toJson.setMsg(e.getMessage());
        }
        return toJson;

    }

    /**
     * @作者: 张航宁
     * @时间: 2019/8/28
     * @说明: 资产设置保存接口
     */
    public ToJson saveSetting(String logoAttachmentId) {
        ToJson<Object> json = new ToJson<Object>();

        SysPara sysPara = sysParaMapper.querySysPara("ASSETS_LOGO_AID");

        if (sysPara != null) {
            sysPara.setParaValue(logoAttachmentId);
            sysParaMapper.updateSysPara(sysPara);
        } else {
            sysPara = new SysPara();
            sysPara.setParaName("ASSETS_LOGO_AID");
            sysPara.setParaValue(logoAttachmentId);
            sysParaMapper.insertSysPara(sysPara);
        }

        json.setFlag(0);
        return json;
    }

    /**
     * @作者: 张航宁
     * @时间: 2019/8/28
     * @说明: 资产设置查询接口
     */
    public ToJson getSetting(HttpServletRequest request) {
        ToJson<Object> json = new ToJson<Object>();
        Map<String, Object> resultMap = new HashMap<String, Object>();

        SysPara sysPara = sysParaMapper.querySysPara("ASSETS_LOGO_AID");

        if (sysPara != null && !StringUtils.checkNull(sysPara.getParaValue())) {
            resultMap.put("logoAid", sysPara.getParaValue());
            ToJson<Attachment> fixAssets = enclosureService.selectByPrimaryKey(Integer.valueOf(sysPara.getParaValue()), "fixAssets", request);
            if (fixAssets.isFlag()) {
                Attachment attachment = (Attachment) fixAssets.getObject();
                resultMap.put("logoUrl", attachment.getAttUrl());
            }
        }

        json.setFlag(0);
        json.setObject(resultMap);
        return json;
    }

    //添加资金类别
    @Transactional
    public ToJson<EduFixAssetsType> insertFixAssetsType(EduFixAssetsType eduFixAssetsType, HttpServletRequest request) {
        ToJson<EduFixAssetsType> json = new ToJson<EduFixAssetsType>(1, "error");
        int count = eduFixAssetsMapper.insertFixAssetsType(eduFixAssetsType);
        if (count > 0) {
            json.setMsg("ok");
            json.setFlag(0);
        }

        return json;
    }

    //根据id删除资金类别
    public ToJson<EduFixAssetsType> delFixAssetsType(Integer typeId) {
        ToJson<EduFixAssetsType> json = new ToJson<EduFixAssetsType>(1, "error");
        try {
            int count = eduFixAssetsMapper.delFixAssetsType(typeId);
            if (count > 0) {
                json.setMsg("ok");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService delFixAssetsType:" + e);
            e.printStackTrace();
        }
        return json;
    }

    //根据id更改资金类别
    @Transactional
    public ToJson<EduFixAssetsType> updateFixAssetsType(EduFixAssetsType eduFixAssetsType, HttpServletRequest request) {
        ToJson<EduFixAssetsType> json = new ToJson<EduFixAssetsType>(1, "error");

        int count = eduFixAssetsMapper.updateFixAssetsType(eduFixAssetsType);
        if (count > 0) {
            json.setMsg("ok");
            json.setFlag(0);
        }

        return json;
    }

    //根据id查询单个资产类别信息
    public ToJson<EduFixAssetsType> selFixAssetsTypeById(Integer typeId) {
        ToJson<EduFixAssetsType> json = new ToJson<EduFixAssetsType>(1, "error");
        try {
            EduFixAssetsType eduFixAssetsType = eduFixAssetsMapper.selFixAssetsTypeById(typeId);
            json.setObject(eduFixAssetsType);
            json.setMsg("ok");
            json.setFlag(0);
        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService selFixAssetsTypeById:" + e);
            e.printStackTrace();
        }
        return json;
    }


    //批量设置设备应急救援类型
    public ToJson<EduFixAssets> updateAssetsType(Integer typeId, String assetIds) {
        ToJson<EduFixAssets> json = new ToJson<EduFixAssets>(1, "error");
        try {
            String[] strings = assetIds.split(",");
            typeId = typeId == 1 ? 1 : 0;
            Integer i = eduFixAssetsMapper.updateAssetsType(typeId, strings);
            if (i != null && i > 0) {
                json.setMsg("ok");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService selFixAssetsTypeById:" + e);
            e.printStackTrace();
        }
        return json;
    }

    public ToJson<CpAssetsApply> insertAssetsApplys(CpAssetsApply cpAssetsApply, HttpServletRequest request) {
        ToJson<CpAssetsApply> json = new ToJson<CpAssetsApply>(1, "error");

        if (StringUtils.checkNull(cpAssetsApply.getApplyType())) {
            cpAssetsApply.setApplyType("apply");
        }
        if (!StringUtils.checkNull(cpAssetsApply.getAssetsId())) {
            EduFixAssets eduFixAssets = eduFixAssetsMapper.selectAssetsByCptlNo(cpAssetsApply.getAssetsId());
            cpAssetsApply.setAssetsId(eduFixAssets.getId());
            cpAssetsApply.setAssetsType(eduFixAssets.getTypeId());
            if (!StringUtils.checkNull(eduFixAssets.getKeeper())){
                Users usersByUid = usersMapper.getUsersByUid(Integer.parseInt(eduFixAssets.getKeeper().substring(0,eduFixAssets.getKeeper().length() -1)));
                cpAssetsApply.setApprover(usersByUid.getUserId());

            }
        }
        cpAssetsApply.setStatus("0");
        int i=0;

            if (StringUtils.checkNull(i+"")){

            }

        int s = cpAssetsApplyMapper.selectCountApply();
        if (s==0){
            i=0;
            cpAssetsApply.setApplyId(i);
        }else {
            i = cpAssetsApplyMapper.selectMaxApplyIdApply();
            cpAssetsApply.setApplyId(i+1);
        }
      /*  if (!StringUtils.checkNull(cpAssetsApply.getRunId()+"")){
            FlowRun flowRun = flowRunMapper.selectByRunId(cpAssetsApply.getRunId());
           // cpAssetsApply.setRunId();
        }*/

        //cpAssetsApply.setBill("ZCSQ20191231101659594");
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionCookie);
        cpAssetsApply.setApplyUser(user.getUserId());
        SmsBody smsBody = new SmsBody();
        smsBody.setFromId(user.getUserId());
        smsBody.setSmsType("74");
        smsBody.setContent("请查看资产审批信息");
        smsBody.setSendTime((int)(System.currentTimeMillis() / 1000));
        smsBody.setRemindUrl("/eduFixAssets/cpfixAssetsApprove?applyId="+cpAssetsApply.getApplyId()+"");
        if(cpAssetsApply.getApprover()!=null) {
            smsService.saveSms(smsBody, (cpAssetsApply.getApprover()+","), "1", "0", "", "", "");
        }

        Map<String,Object> map=new HashedMap();
        map.put("assetsId",cpAssetsApply.getAssetsId());
        //int useRommTotalCount=hstMeetingWithBLOBs.selCountRoomNoConflict(map);//使用要申请的会议室的会议总数
        map.put("receiveAt",cpAssetsApply.getReceiveAt());
        map.put("returnAt",cpAssetsApply.getReturnAt());
        //   int useRommNoConflictCount=meetingMapper.selCountRoomNoConflict(map);//使用要申请会议室和已申请会议室不冲突的数量
        //map.put("roomId",hstMeetingWithBLOBs.getRoomId());
        int nums = cpAssetsApplyMapper.getAssetByTime(map);
        if (nums>=1) {
            json.setMsg("资产已被占用,请重新修改时间");
            json.setFlag(1);
            return json;
        }
        int insert = cpAssetsApplyMapper.insert(cpAssetsApply);
        if (insert > 0) {
            json.setMsg("ok");
            json.setFlag(0);
        }
        return json;
    }


    /**
     * 方法介绍:   添加时获取id
     * 参数说明:   @param id 资产id
     * 返回值说明:
     */
    public ToJson<CpAssetsApply> getFixAssetsApplyId() {
        ToJson<CpAssetsApply> json = new ToJson<CpAssetsApply>(1, "error");
        try {
            String idStr = "ZCSQ" + DateFormat.getDatestr(new Date());
            String s = idStr.replaceAll("-", "");
            String maxId = eduFixAssetsMapper.selectMaxIds(s);
            String OriginId = "00001";
            if (!StringUtils.checkNull(maxId)) {
                String tempId = String.valueOf(Integer.valueOf(maxId.substring(12, maxId.length())) + 1);
                String zeroStr = "";
                for (int i = tempId.length(); i < 6 - tempId.length(); i++) {
                    zeroStr += "0";
                }
                OriginId = zeroStr + tempId;
            }
            String IdStr = "ZCSQ" + DateFormat.getDatestr(new Date()) + OriginId;
            CpAssetsApply eduFixAssets = new CpAssetsApply();
            eduFixAssets.setBill(IdStr.replaceAll("-", ""));
            SimpleDateFormat sdf = new SimpleDateFormat("YYYY-mm-dd");
          /*  Date date = new Date();
            eduFixAssets.setCreaterTime(DateFormat.getDatestr(new Date()));*/
            json.setMsg("ok");
            json.setObject(eduFixAssets);
            json.setFlag(0);
        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService getFixAssetsApplyId:" + e);
            e.printStackTrace();
        }
        return json;
    }

    /**
     * 方法介绍:   添加时获取id
     * 参数说明:   @param id 资产id
     * 返回值说明:
     */
    public ToJson<CpAssetsApply> getFixAssetsApply(String flag2, String flag, String status, String applyId, Integer page, Integer pageSize, boolean useFlag, HttpServletRequest request) {
        ToJson<CpAssetsApply> json = new ToJson<CpAssetsApply>(1, "error");
        try {
            List<CpAssetsApply> cpAssetsApplies = null;
            CpAssetsApply cpAssetsApplys = new CpAssetsApply();
            CpAssetsApply cpAssetsApply2 = new CpAssetsApply();
            Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
            Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionCookie);
            //资产申请
            if ("1".equals(flag)) {
                cpAssetsApplys.setApplyUser(user.getUserId());
                cpAssetsApply2.setApplyUser(user.getUserId());
            }
            //资产审批
            if ("2".equals(flag)) {
                cpAssetsApplys.setApprover(user.getUserId());
                cpAssetsApply2.setApprover(user.getUserId());
            }

            //最近一个月资产申请
            if ("6".equals(flag2)) {
                Calendar calendar = Calendar.getInstance();
                calendar.add(Calendar.DATE, -30);
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String format = dateFormat.format(calendar.getTime());
                Date date = dateFormat.parse(format);
                cpAssetsApplys.setRealTime(date);
                cpAssetsApplys.setRealTime2(new Date());
            }
            //最近一周资产申请
            else if ("5".equals(flag2)) {
                Calendar calendar = Calendar.getInstance();
                calendar.add(Calendar.DATE, -7);
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String format = dateFormat.format(calendar.getTime());
                Date date = dateFormat.parse(format);
                cpAssetsApplys.setRealTime(date);
                cpAssetsApplys.setRealTime2(new Date());
            }
            //最近三天资产申请
            else if ("4".equals(flag2)) {
                Calendar calendar = Calendar.getInstance();
                calendar.add(Calendar.DATE, -3);
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String format = dateFormat.format(calendar.getTime());
                Date date = dateFormat.parse(format);
                cpAssetsApplys.setRealTime(date);
                cpAssetsApplys.setRealTime2(new Date());
            }
            //根据状态查询
            if (!StringUtils.checkNull(applyId)) {
                cpAssetsApplys.setApplyId(Integer.parseInt(applyId));
            }
            PageParams pages = new PageParams();
            pages.setPage(page);
            pages.setPageSize(pageSize);
            pages.setUseFlag(useFlag);
            Map<String, Object> map = new HashMap<String, Object>();
            Map<String, Object> map2 = new HashMap<String, Object>();
            map.put("page", pages);
            if ("6".equals(status)){
                status="";
            }
            cpAssetsApply2.setStatus(status);
            cpAssetsApplys.setStatus(status);
            int count=0;

            if ("1".equals(status)) {
                map.put("cpAssetsApplys", cpAssetsApplys);
                map2.put("cpAssetsApplys", cpAssetsApplys);
                cpAssetsApplies = cpAssetsApplyMapper.selectByApplyUser2(map);
                count = cpAssetsApplyMapper.selectByApplyUser2Count(map2);
            }else{
                map.put("cpAssetsApplys", cpAssetsApplys);
                map2.put("cpAssetsApplys", cpAssetsApplys);
                cpAssetsApplies = cpAssetsApplyMapper.selectByApplyUser(map);
                count = cpAssetsApplyMapper.selectByApplyUserCount(map2);
            }
            /*if ("1".equals(flag)){
                 cpAssetsApplies = cpAssetsApplyMapper.selectByApplyUser(cpAssetsApplys);
            }else if ("2".equals(flag)){
                 cpAssetsApplies = cpAssetsApplyMapper.selectByApprover(cpAssetsApplys);
            }*/
            for (CpAssetsApply cpAssetsApply : cpAssetsApplies) {
               if ("1".equals(cpAssetsApply.getStatus())){
                   long startTime=0;
                   long endTime=0;
                   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                   if(!StringUtils.checkNull(cpAssetsApply.getReceiveAt()+"")){
                       //startTime= meeting.getStartTime().getTime();
                       startTime=Long.valueOf(DateFormat.getTime(sdf.format(cpAssetsApply.getReceiveAt())));
                   }
                   if(!StringUtils.checkNull(cpAssetsApply.getReturnAt()+"")){
                       // endTime= meeting.getEndTime().getTime();
                       endTime=Long.valueOf(DateFormat.getTime(sdf.format(cpAssetsApply.getReturnAt())));

                   }
                   Date date = new Date();
                   long currentTime=Long.valueOf(DateFormat.getTime(sdf.format(date)));
                   if("1".equals(cpAssetsApply.getStatus())){
                       if(startTime<=currentTime && currentTime>=endTime){
                           cpAssetsApply.setStatusString("是超期未归还");
                           cpAssetsApply.setStatus("4");
                       }
                       //对时间进行了判断，修改数据库，并更改返回值
                       cpAssetsApplyMapper.updEduApplyStatusById(cpAssetsApply.getApplyId(),cpAssetsApply.getStatus());
                   }
               }
               if (!StringUtils.checkNull(cpAssetsApply.getAssetsId())){
                   EduFixAssets eduFixAssets = eduFixAssetsMapper.selFixAssetsById(cpAssetsApply.getAssetsId());
                   cpAssetsApply.setEduFixAssets(eduFixAssets);
               }
                if (!StringUtils.checkNull(cpAssetsApply.getAssetsType() + "")) {
                    String typeIdTypeName = eduFixAssetsMapper.getTypeIdTypeName(cpAssetsApply.getAssetsType() + "");
                    cpAssetsApply.setApplyType(typeIdTypeName);
                }
                if (!StringUtils.checkNull(cpAssetsApply.getApprover())) {
                    String usernameByUserId = usersMapper.getUsernameByUserId(cpAssetsApply.getApprover());
                    cpAssetsApply.setApprover(usernameByUserId);
                }
                if (!StringUtils.checkNull(cpAssetsApply.getReturnApprover())) {
                    String usernameByUserId = usersMapper.getUsernameByUserId(cpAssetsApply.getReturnApprover());
                    cpAssetsApply.setReturnApprover(usernameByUserId);
                }
                if (!StringUtils.checkNull(cpAssetsApply.getApplyUser())) {
                    String usernameByUserId = usersMapper.getUsernameByUserId(cpAssetsApply.getApplyUser());
                    cpAssetsApply.setApplyUser(usernameByUserId);
                }
                if (!StringUtils.checkNull(cpAssetsApply.getKeeper())) {
                    String userName = usersMapper.getUsernameByUserId(cpAssetsApply.getKeeper());
                    cpAssetsApply.setKeeper(userName);
                }
                if (!StringUtils.checkNull(cpAssetsApply.getDeptId())) {
                    Department deptById = departmentMapper.getDeptById(Integer.parseInt(cpAssetsApply.getDeptId()));
                    if (deptById!=null) {
                        cpAssetsApply.setDeptName(deptById.getDeptName());
                    }
                }
                Date date=new Date();
                Calendar  newDate  =  Calendar.getInstance();
                newDate.setTime(date);
                int newYear = newDate.get(Calendar.YEAR);
                int newMonth = newDate.get(Calendar.MONTH);

                if(!StringUtils.checkNull(cpAssetsApply.getReceiveAt()+"")){
                    Calendar  from  =  Calendar.getInstance();
                    from.setTime(cpAssetsApply.getReceiveAt());
                    int fromYear = from.get(Calendar.YEAR);
                    int fromMonth = from.get(Calendar.MONTH);
                    Calendar  to  =  Calendar.getInstance();
                    to.setTime(cpAssetsApply.getReturnAt());
                    int toYear = to.get(Calendar.YEAR);
                    int toMonth = to.get(Calendar.MONTH);
                    int month = newYear *  12  + newMonth  -  (fromYear  *  12  +  fromMonth);
                    if (month<=0){
                        int month2 = toYear *  12  + toMonth  -  (fromYear  *  12  +  fromMonth);
                        cpAssetsApply.setRemainingMonths(month2+"");
                    }else {
                        if ((newYear  *  12  +  newMonth)-(toYear *  12  + toMonth)>=0){
                            cpAssetsApply.setRemainingMonths(0+"");
                        }else {
                            cpAssetsApply.setRemainingMonths(month+"");
                        }
                    }
                }
                if(!StringUtils.checkNull(cpAssetsApply.getReturnAt()+"")){
                    Calendar  to  =  Calendar.getInstance();
                    to.setTime(cpAssetsApply.getReturnAt());
                    int toYear = to.get(Calendar.YEAR);
                    int toMonth = to.get(Calendar.MONTH);
                    int month = toYear *  12  + toMonth  -  (newYear  *  12  +  newMonth);
                    Calendar  from  =  Calendar.getInstance();
                    from.setTime(cpAssetsApply.getReceiveAt());
                    int fromYear = from.get(Calendar.YEAR);
                    int fromMonth = from.get(Calendar.MONTH);
                    int month3 = newYear *  12  + newMonth  -  (fromYear  *  12  +  fromMonth);
                    if (month<=0){
                        cpAssetsApply.setUseMonths(toYear *  12  + toMonth  -  (fromYear  *  12  +  fromMonth)+"");
                    }else {
                        if (month3>=0){
                            cpAssetsApply.setUseMonths(month3+"");
                        }else{
                            cpAssetsApply.setUseMonths(0+"");
                        }

                    }
                }
            }
            json.setTotleNum(count);
            json.setMsg("ok");
            json.setObject(cpAssetsApplies);
            json.setFlag(0);
        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService getFixAssetsApply:" + e);
            e.printStackTrace();
        }
        return json;

    }

    //根据id删除资产申请
    public ToJson<CpAssetsApply> delFixAssetsApply(Integer applyId) {
        ToJson<CpAssetsApply> json = new ToJson<CpAssetsApply>(1, "error");
        try {
            int count = cpAssetsApplyMapper.deleteByPrimaryKey(applyId);
            if (count > 0) {
                json.setMsg("ok");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService delFixAssetsApply:" + e);
            e.printStackTrace();
        }
        return json;
    }

    //归还资产
    public ToJson<CpAssetsApply> returnFixAssetsApply(Integer applyId, String status,HttpServletRequest request) {
        ToJson<CpAssetsApply> json = new ToJson<CpAssetsApply>(1, "error");
        try {
            if (!StringUtils.checkNull(applyId + "")) {
                if ("3".equals(status)) {
                    Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
                    Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionCookie);
                    CpAssetsApply cpAssetsApply = new CpAssetsApply();
                    cpAssetsApply.setApplyId(applyId);
                    cpAssetsApply.setStatus(status);
                    cpAssetsApply.setRealReturnAt(new Date());
                    cpAssetsApply.setReturnApprover(user.getUserId());

                    int count = cpAssetsApplyMapper.updateByPrimaryKeySelective(cpAssetsApply);
                    SmsBody smsBody = new SmsBody();
                    smsBody.setContent("您有固定资产需要验收");
                    smsBody.setFromId(user.getUserId());
                    smsBody.setSmsType("74");

                    smsBody.setSendTime((int)(System.currentTimeMillis() / 1000));
                    smsBody.setRemindUrl("/eduFixAssets/cpfixAssetsApprove?applyId="+applyId+"");
                    if(cpAssetsApply.getApprover()!=null) {
                        smsService.saveSms(smsBody, cpAssetsApply.getApprover(), "1", "0", "", "", "");
                    }
                    if (count > 0) {
                        json.setMsg("ok");
                        json.setFlag(0);
                    }
                }
            }

        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService delFixAssetsApply:" + e);
            e.printStackTrace();
        }
        return json;
    }

    //资产验收
    public ToJson<CpAssetsApply> receiveFixAssetsApply(Integer applyId, String status,HttpServletRequest request) {
        ToJson<CpAssetsApply> json = new ToJson<CpAssetsApply>(1, "error");
        try {
            Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
            Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionCookie);
            if (!StringUtils.checkNull(applyId + "")) {
                if ("5".equals(status)) {
                    CpAssetsApply cpAssetsApply = new CpAssetsApply();
                    cpAssetsApply.setApplyId(applyId);
                    cpAssetsApply.setStatus(status);
                    int count = cpAssetsApplyMapper.updateByPrimaryKeySelective(cpAssetsApply);
                    if (count >0){
                        Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
                        Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionId);
                        smsMapper.setReadByUrl(users.getUserId(),"/eduFixAssets/cpfixAssetsApprove?applyId="+applyId+"");
                    }
                    SmsBody smsBody = new SmsBody();
                    smsBody.setContent("您有固定资产已被验收");
                    smsBody.setFromId(user.getUserId());
                    smsBody.setSmsType("74");
                    smsBody.setSendTime((int)(System.currentTimeMillis() / 1000));
                    smsBody.setRemindUrl("/eduFixAssets/getFixAssetsApply");
                    if(cpAssetsApply.getApprover()!=null) {
                        smsService.saveSms(smsBody, cpAssetsApply.getApprover(), "1", "0", "", "", "");
                    }
                    if (count > 0) {
                        json.setMsg("ok");
                        json.setFlag(0);
                    }
                }
            }

        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService delFixAssetsApply:" + e);
            e.printStackTrace();
        }
        return json;
    }


    //资产审批
    public ToJson<CpAssetsApply> approveFixAssetsApply(Integer applyId, String status,HttpServletRequest request) {
        ToJson<CpAssetsApply> json = new ToJson<CpAssetsApply>(1, "error");
        try {
            if (!StringUtils.checkNull(applyId + "")) {
                Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
                Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionCookie);
                    CpAssetsApply cpAssetsApply = new CpAssetsApply();
                    cpAssetsApply.setApplyId(applyId);
                    cpAssetsApply.setStatus(status);
                    /*cpAssetsApply.setApprover(user.getUserId());*/
                    cpAssetsApply.setApprovelTime(new Date());
                    int count = cpAssetsApplyMapper.updateByPrimaryKeySelective(cpAssetsApply);
                    if (count >0){
                        Cookie redisSessionId = CookiesUtil.getCookieByName(request, "redisSessionId");
                        Users users = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionId);
                        smsMapper.setReadByUrl(users.getUserId(),"/eduFixAssets/cpfixAssetsApprove?applyId="+applyId+"");
                    }
                    SmsBody smsBody = new SmsBody();
                    if ("1".equals(status)){
                        smsBody.setContent("您的固定资产申请已被批准");
                    }else if ("2".equals(status)){
                        smsBody.setContent("您的固定资产申请未被批准");
                    }
                    smsBody.setFromId(user.getUserId());
                    smsBody.setSmsType("74");

                    smsBody.setSendTime((int)(System.currentTimeMillis() / 1000));
                    smsBody.setRemindUrl("/eduFixAssets/getFixAssetsApply");
                if(cpAssetsApply.getApprover()!=null) {
                    smsService.saveSms(smsBody, cpAssetsApply.getApplyUser(), "1", "0", "", "", "");
                }
                    if (count > 0) {
                        json.setMsg("ok");
                        json.setFlag(0);
                    }
            }

        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService delFixAssetsApply:" + e);
            e.printStackTrace();
        }
        return json;
    }
    //新建资产盘点
    public ToJson<CpAssetsApply> fixAssetsInventory(CpAssetsInventory cpAssetsInventory, HttpServletRequest request) {
        ToJson<CpAssetsApply> json = new ToJson<CpAssetsApply>(1, "error");
        try {
            Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
            Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionCookie);
            String idStr =DateFormat.getDatestr(new Date());
            String s = idStr.replaceAll("-", "");
            String maxId = eduFixAssetsMapper.selectMaxIdss(s);
            String OriginId = "001";
            if (!StringUtils.checkNull(maxId)) {
                String tempId = String.valueOf(Integer.valueOf(maxId.substring(8, maxId.length())) + 1);
                String zeroStr = "";
                for (int i = tempId.length(); i < 4 - tempId.length(); i++) {
                    zeroStr += "0";
                }
                OriginId = zeroStr + tempId;
            }
            String IdStr =DateFormat.getDatestr(new Date()) + OriginId;
            String s1 = IdStr.replaceAll("-", "");
           // cpAssetsInventory.setOperator(user.getUserId());
            cpAssetsInventory.setInventoryTime(new Date());
            cpAssetsInventory.setInventoryId(s1);
            int count = cpAssetsInventoryMapper.insert(cpAssetsInventory);
            int insert=0;
            cpAssetsInventory.setApplyUser(cpAssetsInventory.getApplyUser().substring(0,cpAssetsInventory.getApplyUser().length() -1));
            List<CpAssetsInventoryRecords> cpAssetsInventoryRecords = cpAssetsInventoryMapper.selectByCpAssets(cpAssetsInventory);
            for (CpAssetsInventoryRecords cpAssetsInventoryRecords1:cpAssetsInventoryRecords){
                if (StringUtils.checkNull(cpAssetsInventoryRecords1.getIsInventory())){
                    cpAssetsInventoryRecords1.setIsInventory("1");
                }
                if (StringUtils.checkNull(cpAssetsInventoryRecords1.getCreateTime()+"")){
                    cpAssetsInventoryRecords1.setCreateTime(new Date());
                }
                if (!StringUtils.checkNull(cpAssetsInventory.getInventoryTime()+"")) {
                    cpAssetsInventoryRecords1.setInventoryId(s1);
                }
                cpAssetsInventoryRecords1.setCreateTime(new Date());
                insert = cpAssetsInventoryRecordsMapper.insert(cpAssetsInventoryRecords1);
            }
            if (count > 0 ) {
                json.setMsg("ok");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService delFixAssetsApply:" + e);
            e.printStackTrace();
        }
        return json;
    }
    public ToJson<CpAssetsInventory> fixAssetsGetInventory(HttpServletRequest request, String inventoryId,String type,Integer page, Integer limit, Boolean useFlag){
        ToJson<CpAssetsInventory> json = new ToJson<CpAssetsInventory>(1, "error");
        try {
            Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
            Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionCookie);
            CpAssetsInventory cpAssetsInventory=new CpAssetsInventory();
            CpAssetsInventoryRecords cpAssetsInventoryRecords=new CpAssetsInventoryRecords();
            if(!StringUtils.checkNull(inventoryId)){
                cpAssetsInventory.setInventoryId(inventoryId);
                cpAssetsInventoryRecords.setInventoryId(inventoryId);
            }
            PageParams pages = new PageParams();
            pages.setPage(page);
            pages.setPageSize(limit);
            pages.setUseFlag(useFlag);
            Map<String, Object> map = new HashMap<String, Object>();
            Map<String, Object> map2 = new HashMap<String, Object>();
            Map<String, Object> map3 = new HashMap<String, Object>();
            map3.put("page", pages);
            map3.put("cpAssetsInventoryRecords",cpAssetsInventoryRecords);
            map.put("page", pages);
            cpAssetsInventory.setOperator(user.getName());
            if ("2".equals(type)){
                List<CpAssetsInventoryRecords> cpAssetsInventories = cpAssetsInventoryRecordsMapper.selectCountByInventoryId(map3);
                    int i = cpAssetsInventoryRecordsMapper.selectByInventoryId(cpAssetsInventoryRecords);
                for (CpAssetsInventoryRecords cpAssetsInventoryRecords1:cpAssetsInventories){
                    if (!StringUtils.checkNull(cpAssetsInventoryRecords1.getAssetsType() + "")) {
                        String typeIdTypeName = eduFixAssetsMapper.getTypeIdTypeName(cpAssetsInventoryRecords1.getAssetsType() + "");
                        cpAssetsInventoryRecords1.setAssetsType(typeIdTypeName);
                    }
                    if (!StringUtils.checkNull(cpAssetsInventoryRecords1.getApplyUser())) {
                        String usernameByUserId = usersMapper.getUsernameByUserId(cpAssetsInventoryRecords1.getApplyUser());
                        cpAssetsInventoryRecords1.setApplyUser(usernameByUserId);
                    }
                    if (!StringUtils.checkNull(cpAssetsInventoryRecords1.getManagers())) {
                        String usernameByUserId = usersMapper.getUsernameByUserId(cpAssetsInventoryRecords1.getManagers());
                        cpAssetsInventoryRecords1.setManagers(usernameByUserId);
                    }

                }
                json.setTotleNum(i);
                json.setMsg("ok");
                json.setFlag(0);
                json.setObject(cpAssetsInventories);
            }else {
                map.put("cpAssetsInventory", cpAssetsInventory);
                map2.put("cpAssetsInventory", cpAssetsInventory);

                List<CpAssetsInventory> cpAssetsInventories = cpAssetsInventoryMapper.selectByOperator(map);
                for (CpAssetsInventory cpAssetsInventory1:cpAssetsInventories){
                    if (!StringUtils.checkNull(cpAssetsInventory1.getAssetsType() + "")) {
                        String typeIdTypeName = eduFixAssetsMapper.getTypeIdTypeName(cpAssetsInventory1.getAssetsType() + "");
                        cpAssetsInventory1.setAssetsType(typeIdTypeName);
                    }
                    if (!StringUtils.checkNull(cpAssetsInventory1.getApplyUser())) {

                        String usernameByUserId = usersMapper.getUsernameByUserId(cpAssetsInventory1.getApplyUser().substring(0,cpAssetsInventory1.getApplyUser().length() -1));
                        cpAssetsInventory1.setApplyUser(usernameByUserId);
                    }
                    if (!StringUtils.checkNull(cpAssetsInventory1.getManagers())) {
                        String usernameByUserId = usersMapper.getUsernameByUserId(cpAssetsInventory1.getManagers());
                        cpAssetsInventory1.setManagers(usernameByUserId);
                    }
                    if (!StringUtils.checkNull(cpAssetsInventory1.getOperator())) {
                        String usernameByUserId = usersMapper.getUsernameByUserId(cpAssetsInventory1.getOperator().substring(0,cpAssetsInventory1.getOperator().length() -1));
                        cpAssetsInventory1.setOperator(usernameByUserId);
                    }

                }
                int i = cpAssetsInventoryMapper.selectByOperatorCount(map2);
                json.setTotleNum(i);
                json.setMsg("ok");
                json.setFlag(0);
                json.setObject(cpAssetsInventories);
            }

        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService fixAssetsGetInventory:" + e);
            e.printStackTrace();
        }
        return json;
    }

        public ToJson<EduFixAssets> fixAssetsList( Integer page, Integer pageSize, Boolean useFlag){
        ToJson<EduFixAssets> json = new ToJson<EduFixAssets>(1, "error");
        try {
            PageParams pageParams = new PageParams();
            pageParams.setPage(page);
            pageParams.setPageSize(pageSize);
            pageParams.setUseFlag(useFlag);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("page", pageParams);
            EduFixAssets eduFixAssets=new EduFixAssets();
            map.put("eduFixAssets",eduFixAssets);
            List<EduFixAssets> eduFixAssetss = eduFixAssetsMapper.selAssetsByCond(map);
            for (EduFixAssets eduFixAssets1:eduFixAssetss){
                if (!StringUtils.checkNull(eduFixAssets1.getTypeId() + "")) {
                    String typeIdTypeName = eduFixAssetsMapper.getTypeIdTypeName(eduFixAssets1.getTypeId() + "");
                    eduFixAssets1.setTypeIdStr(typeIdTypeName);
                }
                if(!StringUtils.checkNull(eduFixAssets1.getValidityTime()+"")){
                    Calendar calendar = Calendar.getInstance();
                    calendar.add(Calendar.DATE, +Integer.parseInt(eduFixAssets1.getUseYy()));
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                   // String format = dateFormat.format(calendar.getTime());
                    String format=eduFixAssets1.getValidityTime();
                    Date date = new Date();
                    String format1 = dateFormat.format(date);
                    String [] split= (format).split("-");
                    String [] split2= (format1).split("-");
                    int a=0;
                    int b=0;
                    int c=0;
                    int d=0;
                    int f=0;
                    StringBuffer stringBuffer=new StringBuffer();
                    int x = 0;
                    for (String s1 : split) {
                        if (x ==0) {
                            a=Integer.parseInt(s1);
                        }
                        if (x==1){
                            b=Integer.parseInt(s1);
                        }
                        x++;
                    }
                    int x1 = 0;
                    for (String s1 : split2) {
                        if (x1 ==0) {
                            c=Integer.parseInt(s1);
                        }
                        if (x1==1){
                           d=Integer.parseInt(s1);
                        }
                        x1++;
                    }
                         f=(a-c)*12+b-d;
                    if (f<=0){
                        eduFixAssets1.setUserYyyy(0+"");
                    }else {
                        eduFixAssets1.setUserYyyy(f+"");
                    }
                }
            }
            json.setMsg("ok");
            json.setFlag(0);
            json.setObject(eduFixAssetss);
        } catch (Exception e) {
            json.setMsg(e.getMessage());
            L.e("EduFixAssetsService fixAssetsGetInventory:" + e);
            e.printStackTrace();
        }
        return json;
    }


    public ToJson<EduFixAssetsType> getAllFixAssetsType(){
        ToJson<EduFixAssetsType> json = new ToJson<EduFixAssetsType>(1, "error");
        try {
            List<EduFixAssetsType> fixAssetstypeName = eduFixAssetsMapper.getFixAssetstypeName();
            json.setMsg("ok");
            json.setFlag(0);
            json.setObject(fixAssetstypeName);
        } catch (Exception e) {
            json.setMsg("error");
            json.setFlag(0);
        }
        return json;
    }
    public ToJson<EduFixAssetsType> fixAssetsSummary(Integer page, Integer limit, Boolean useFlag){
        ToJson<EduFixAssetsType> json = new ToJson<EduFixAssetsType>(1, "error");
        try {
            useFlag=true;
            PageParams pageParams = new PageParams();
           pageParams.setPage(page);
            pageParams.setPageSize(limit);
            pageParams.setUseFlag(useFlag);
            Map<String, Object> map2 = new HashMap<String, Object>();
            map2.put("page", pageParams);
            List<EduFixAssetsType> fixAssetstypeName = eduFixAssetsMapper.getFixAssetstypeName2(map2);
            int count = eduFixAssetsMapper.getFixAssetstypeNameCount();
            for (EduFixAssetsType eduFixAssetsType:fixAssetstypeName){
                Map<String,Object> map=new HashMap();
                EduFixAssets eduFixAssets=new EduFixAssets();
                eduFixAssets.setTypeId(Integer.parseInt(eduFixAssetsType.getTypeId()));
                eduFixAssets.setTypeIdStr(eduFixAssetsType.getTypeId());
                map.put("eduFixAssets", eduFixAssets);
                List<EduFixAssets> eduFixAssets1 = eduFixAssetsMapper.selAssetsByCond(map);
                Integer integer = eduFixAssetsMapper.selAssetsSumCptlVal(map);
                Integer integer1 = eduFixAssetsMapper.selAssetsSumCptlBalVal(map);
                Integer integer2 = eduFixAssetsMapper.selAssetsByCount(map);
                eduFixAssetsType.setPriceTotal(integer2+"");
                eduFixAssetsType.setCptlValTotal(integer+"");
                eduFixAssetsType.setCptlBalTotal(integer1+"");
                if (eduFixAssetsType.getCptlBalTotal().equals("null")){
                    eduFixAssetsType.setCptlBalTotal("0");
                }
                if (eduFixAssetsType.getCptlValTotal().equals("null")){
                    eduFixAssetsType.setCptlValTotal("0");
                }
                /*eduFixAssetsMapper.selAssetsByOrCond();*/
            }
            json.setMsg("ok");
            json.setFlag(0);
            json.setObject(fixAssetstypeName);
            json.setTotleNum(count);

        } catch (Exception e) {
            json.setMsg("查询失败");
            json.setFlag(0);
        }
        return json;
    }
    @Async
    public void addAssetAffairs1(final CpAssetsApply cpAssetsApply, HttpServletRequest request) {
        final String sqlType = (String) request.getSession().getAttribute("loginDateSouse");
        Cookie redisSessionId = CookiesUtil.getCookieByName(request,"redisSessionId");
        Users users = SessionUtils.getSessionInfo(request.getSession(),Users.class,new Users(),redisSessionId);
        final String userName = users.getUserName();
        this.threadPoolTaskExecutor.execute(new Runnable() {
            @Override
            public void run() {
                ContextHolder.setConsumerType("xoa" + sqlType);
                SmsBody smsBody = new SmsBody();
                smsBody.setFromId(cpAssetsApply.getApplyUser());
//                smsBody.setContent("固定资产:当前资产已经审批结束");
//                if(!StringUtils.checkNull(meetingWithBLOBs.getStartTime())){
//                    smsBody.setSendTime(DateFormat.getDateTime(meetingWithBLOBs.getStartTime()));
//                }
                smsBody.setSendTime(DateFormat.getTime(DateFormat.getCurrentTime()));
                String toUid="";
                if(!StringUtils.checkNull(cpAssetsApply.getApprover())){
                    toUid+=cpAssetsApply.getApprover();
                }
                String toUserId="";
                if(!StringUtils.checkNull(toUid)){
                    String[] toUidArr=toUid.split(",");
                    for(String uid:toUidArr){
                        toUserId+=uid+",";
                    }
                }
                //去重
               /* if(!StringUtils.checkNull(toUserId)){
                    String[] userArr=toUserId.split(",");
                    List<String> list = new ArrayList<>();
                    list.add(userArr[0]);
                    for(int i=1;i<userArr.length;i++){
                        if(list.toString().indexOf(userArr[i]) == -1){
                            list.add(userArr[i]);
                        }
                    }
                    toUserId="";
                    for(String temp:list){
                        toUserId+=temp+",";
                    }
                }*/
                SysCode sysCode = new SysCode();
                sysCode.setCodeName("固定资产");
                sysCode.setParentNo("SMS_REMIND");
                smsBody.setSmsType("74");
                smsBody.setRemindUrl("/eduFixAssets/cpfixAssetsApprove");
                String title = userName + "：固定资产！";
                String context = "主题:" + "请查看资产审批信息";
                smsService.saveSms(smsBody, toUserId, "1", "1", title, context, sqlType);
            }
        });

    }
}